package com.fatan.demo

import android.Manifest
import android.app.Activity
import android.content.Context
import android.util.Log
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import ohos.ace.plugin.taskmanagerplugin.IConstant.TAG
import java.io.IOException

object Utils {
    fun readJsonFromAssets(context: Context, fileName: String): String? {
        return try {
            val inputStream = context.assets.open(fileName)
            val size = inputStream.available()
            val buffer = ByteArray(size)
            inputStream.read(buffer)
            inputStream.close()
            String(buffer, charset("UTF-8"))
        } catch (e: IOException) {
            e.printStackTrace()
            null
        }
    }

    fun requestPermission(activity:Activity) {
        XXPermissions.with(activity).permission(Permission.MANAGE_EXTERNAL_STORAGE).request(
            object : OnPermissionCallback {
                override fun onGranted(permissions: MutableList<String>, allGranted: Boolean) {
                    Log.i(TAG, "onGranted: ")
                }

                override fun onDenied(permissions: MutableList<String>, doNotAskAgain: Boolean) {
                    super.onDenied(permissions, doNotAskAgain)
                    Log.i(TAG, "onDenied: ")
                }
            })
    }
}